#include "en_decode.h"
#include "base64.h"

using namespace std;

std::string base64_encode(const unsigned char* in, unsigned int inlen)
{
    int outlen = BASE64_ENCODE_OUT_SIZE(inlen);
    char* out = new char[outlen];
    memset(out, 0, outlen);
    int len = hv_base64_encode(in, inlen, out);
    string str(out);
    delete [] out;
    out = nullptr;
    return str;
}

std::string base64_encode(const std::string& in)
{
    return base64_encode((const unsigned char*)in.c_str(), in.length());
}

std::string base64_decode(const char* in, unsigned int inlen)
{
    unsigned int outlen = BASE64_DECODE_OUT_SIZE(inlen);
    unsigned char* out = new unsigned char[outlen];
    memset(out, 0, outlen);
    int len = hv_base64_decode(in, inlen, out);
    string str((char*)out);
    delete [] out;
    out = nullptr;
    return str;
}

std::string base64_decode(const std::string &in)
{
    return base64_decode((const char*)in.c_str(), in.length());
}